package com.cong.lru;

import java.util.LinkedHashMap;
import java.util.Map;

public class MyLruCache<K,V> extends LinkedHashMap<K,V> {

    private int capacity;

    public MyLruCache(int capacity) {
        super(capacity,0.75F,true);
        this.capacity = capacity;
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
        return super.size()>capacity;
    }

    public static void main(String[] args) {
        MyLruCache<String, String> lruCache = new MyLruCache<>(3);
        lruCache.put("1","1");
        lruCache.put("2","1");
        lruCache.put("3","1");
        lruCache.get("1");
        System.out.println(lruCache.keySet());
        lruCache.put("4","4");
        System.out.println(lruCache.keySet());
        System.out.println(lruCache.keySet());

    }
}
